package com.esd.crm.service.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.esd.crm.entity.Project;
import com.esd.crm.mapper.ProjectMapper;
import com.esd.crm.service.ProjectService;
import com.esd.crm.util.KitService;
import com.esd.vo.PageUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

@Service
public class ProjectServiceImpl implements ProjectService{
	
	private static Logger logger = Logger.getLogger(ProjectServiceImpl.class);
	@Autowired
	private ProjectMapper projectDao;

	@Override
	public boolean insertSelective(Project project) {
		if (project == null) {
			logger.info("ProjectServiceImpl.save: 对象为空");
			return Boolean.FALSE;
		} else {
			if (StringUtils.isBlank(project.getId())) {
				project.setId(KitService.getUUID());
			}
			Date date = new Date();
			project.setCreatetime(date);
			project.setUpdatetime(date);
			project.setPhotoPath("_" + project.getId());
		}
		return  projectDao.insertSelective(project);
	}

	@Override
	public boolean deleteById(String projectId) {
		return projectDao.deleteByPrimaryKey(projectId);
	}

	@Override
	public boolean updateByPrimaryKeySelective(Project project) {
		Date date = new Date();
		project.setUpdatetime(date);
		return projectDao.updateByPrimaryKeySelective(project);
	}

	@Override
	public List<Project> findAll(Project project) {
		return projectDao.findAll(project);
	}

	@Override
	public PageInfo<Project> findProjectByPage(Project project, PageUtil page) {
		PageHelper.startPage(page.getNowPage(), page.getNowRows());
		List<Project> projects = projectDao.findAll(project);
		PageInfo<Project> pageInfo = new PageInfo<>(projects);
		return pageInfo;
	}

	@Override
	public boolean deleteBatch(String[] ids) {
		return projectDao.deleteBatch(ids);
	}

	@Override
	public Project findOneProject(String id) {
		return projectDao.findOneProject(id);
	}
	
	@Override
	public List<Project> findOneProject1(String id) {
		return projectDao.findOneProject1(id);
	}
	
	@Override
	public List<Project> selectAllProject(){
		return projectDao.selectAllProject();
	}
	

}
